package com.tptech.nearme.data;

import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

import com.tptech.nearme.model.User;

@TransactionAttribute(TransactionAttributeType.SUPPORTS)
public class UserRepository extends BaseRepository<User>{

//	private static Logger logger = Logger.getLogger(UserRepository.class);
	public UserRepository() {
		super(User.class);
	}
	
	public User findByName(String username){
		
		EntityManager manager = getEntityManager();
		TypedQuery<User> query = manager.createQuery("Select u from User u where username=:username",User.class);
		query.setParameter("username", username);
		User user = query.getSingleResult();
		return user;
	}

	@TransactionAttribute(TransactionAttributeType.REQUIRED)
	public User loadUser(Long userid){
		User user = find(userid);
		System.out.println(user.getPreferredLocations());		
		return user;
	}
	
	
}
